package models

import (
	"gorm.io/gorm"
	"ke-srv/basic/config"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:varchar(30);comment:'手机号'"`
	Password string `gorm:"type:varchar(32);comment:'密码'"`
	Status   int    `gorm:"type:int;default:1;comment:'类型: 1用户 2管理员'"`
}

func (u *User) TableName() string {
	return "user"
}

// 获取用户信息
func (u *User) GetUserInfo(mobile string) error {
	return config.DB.Where("mobile = ?", mobile).Limit(1).Find(&u).Error
}

// 获取用户id
func (u *User) GetUserById(userId int) error {
	return config.DB.Where("id = ?", userId).Limit(1).Find(&u).Error
}

// 用户注册
func (u *User) RegisterUser() error {
	return config.DB.Create(&u).Error
}
